package com.example.listviewtest;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ListView listView = findViewById(R.id.lvAnimals);
        String[] animals = {"子鼠", "丑牛", "寅虎", "卯兔", "辰龙", "巳蛇", "午马", "未羊", "申猴", "酉鸡", "戌狗", "亥猪"};
        String[] englishName = {"Rat charm", "Ox patient", "Tiger sensitive", "Rabbit articulate", "Dragon healthy", "Snake deep", "Horse popular", "Goat elegant", "Monkey clever", "Rooster deep thinkers", "Dog loyalty", "Pig chivalrous"};

        List<Animal> animal = new ArrayList<>();
        for (int j = 0; j < 2; j++) {
            for (int i = 0; i < animals.length; i++) {
                Animal animal1 = new Animal(animals[i], englishName[i]);
                animal.add(animal1);
            }
        }

        AnimalAdapter animalAdapter = new AnimalAdapter(MainActivity.this, R.layout.item, animal);
        listView.setAdapter(animalAdapter);
    }
}